<?php
require_once('../practice/db.php');

pr($_SERVER['HTTP_REFERER']);

pr($_POST);
pr($_FILES);

if($_FILES['path']['error'] == 0) {

  $file_name = date('ymdHis').'_'.rand().'_'.$_FILES['path']['name'];
  $source = $_FILES['path']['tmp_name'];
  $dest = "uploads/$file_name";

  $isUploaded = move_uploaded_file($source, $dest);
  if($isUploaded == true){
    $data['title'] = $_POST['title'];
    $data['path'] = $file_name;
    $data['uploaded_date'] = date('Y-m-d H:i:s');

    ////////////////////////////////
    insert('uploaded_images', $data);
    ////////////////////////////////
    echo "<h1>Congrats !! you have successfully uploaded one filee.</h1>";
  } else {
    echo "<h1>Your Bad !!</h1>";
  }
} else {
  echo "<h4>Something went wrong!! :( </h4>";
}
